package cn.kgc.controller;

import cn.kgc.pojo.User;
import cn.kgc.service.UserService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

@Controller
@RequestMapping("user")
public class UserController {

    @Resource
    UserService userService;

    @RequestMapping("login")
    public  String login(String username, String userpassword, HttpServletRequest request, Model model) {
        User login = userService.login(username, userpassword);
        if (login != null) {
            request.getSession().setAttribute("login",login);
            return  "redirect:/jsp/body/index.jsp";
        }else{
            /*model.addAttribute("error","账号或密码错误!");*/
          /*  request.getSession().setAttribute("login",login);*/
            model.addAttribute("login",username);
            model.addAttribute("error","账号或密码错误");
            return "index";
        }
    }


    @RequestMapping(value = "regist",method =RequestMethod.POST)
    public String regist(User user){

        userService.AddUser(user);
        return "redirect:/jsp/index.jsp";
    }


    /*接下来写邮箱Email*/
/*        @RequestMapping("email")*/

    
}
